package com.sojson.project.pay.controller.ali;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sojson.config.exception.TransErrorCode;
import com.sojson.project.dao.OrderChildDao;
import com.sojson.project.dao.OrderDao;
import com.sojson.project.dao.OrderDepositDao;
import com.sojson.project.pay.controller.param.verify.PayParamVerify;
import com.sojson.project.pay.service.ali.PayAliWapService;
import com.sojson.result.Result;
import com.sojson.util.ExpUtil;
import com.sojson.util.pay.ali.bean.AliResult;
import com.sojson.util.servlet.ServletUtil;

import io.swagger.annotations.Api;

/**
 * 支付宝Wap支付控制器
 * 
 * @author liu
 * @date 2021-03-24
 */
@Api(tags = "支付宝Wap支付管理")
// @RestController
@RequestMapping(value = "/payAliWap")
public class PayAliWapController {

    @Autowired
    private PayAliWapService payAliWapService;
    @Resource
    private OrderDao orderDao;
    @Resource
    private OrderChildDao orderChildDao;
    @Resource
    private OrderDepositDao orderDepositDao;

    /**
     * 商城购物车调起支付
     * 
     * @param nos
     * @return 
     * @throws Exception 
     */
    @PostMapping("/goodsShop/{nos}")
    @PreAuthorize("@ss.login()")
    public void appOrders(@PathVariable String[] nos) throws Exception {
        // 校验参数
        Result<?> paramResult = PayParamVerify.goodsShop(nos);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            ExpUtil.throwEx(paramResult.getMsg());
        }

        AliResult result = payAliWapService.goodsShop(nos);
        ServletUtil.outHtml(result.getBody());
    }

    /**
     * 诚意金调起支付
     * 
     * @param orderId
     * @return 
     * @throws Exception 
     */
    @GetMapping("/deposit/{orderId}")
    // @PreAuthorize("@ss.login()")
    public void deposit(@PathVariable String orderId) throws Exception {
        // 校验参数
        Result<?> paramResult = PayParamVerify.deposit(orderId);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            ExpUtil.throwEx(paramResult.getMsg());
        }

        AliResult result = payAliWapService.deposit(orderId);
        ServletUtil.outHtml(result.getBody());
    }

}